#!/bin/bash
# File init.sh

if [ $# -ne 1 ];
then
        echo '请输入正确的参数d:development, p:production, t:testing'
        exit 1
fi

if [[ $1 != 'd' ]]&&[[ $1 != 'p' ]]&&[[ $1 != 't' ]];
then
        echo '请输入正确的参数d:development, p:production,t:production'
        exit 1
fi
BASEDIR="$( dirname "$0" )"

(cd $BASEDIR/application/config&&cp config.php.bak config.php)

if [ $1 = 'p' ];
then
        sed 's/http:\/\/my./http:\/\//g' application/config/config.php.bak > application/config/config.php
        sed 's/"development"/"production"/g' index.php.bak > index.php
fi

if [ $1 = 't' ];
then
		(cd $BASEDIR/application/config&&cp config.php.bak config.php)
        sed 's/"development"/"testing"/g' index.php.bak > index.php
fi

if [ $1 = 'd' ];
then
        (cd $BASEDIR/application/config&&cp config.php.bak config.php)
        cp index.php.bak index.php
fi

(cd $BASEDIR && mkdir -p uploads resource && chmod -R 777 uploads resource application/cache application/logs)
